package com.tc.property.impl;

import java.util.Collection;
import java.util.Enumeration;
import java.util.List;
import java.util.Properties;

import com.tc.property.PropertyHolder;
import com.tc.property.PropertyManager;
import com.tc.property.support.PropertiesUtils;
import com.tc.property.config.handler.PropertyChangedHandler;
import lombok.Getter;
import lombok.Setter;

import org.springframework.beans.factory.InitializingBean;


public class PropertyManagerImpl implements PropertyManager, InitializingBean {

	@Getter
	@Setter
	private List<PropertyChangedHandler> handlers;

	@Override
	public void afterPropertiesSet() throws Exception {
		if (handlers != null) {
			PropertiesUtils.getContextChangedHandler().setHandlers(handlers);
		}
	}

	@Override
	public String getProperty(String key) {
		Properties properties = PropertyHolder.getProperties();
		return properties.getProperty(key);
	}

	@Override
	public String getProperty(String key, String defaultValue) {
		Properties properties = PropertyHolder.getProperties();
		return properties.getProperty(key, defaultValue);
	}

	@Override
	public Enumeration<Object> keys() {
		Properties properties = PropertyHolder.getProperties();
		return properties.keys();
	}

	@Override
	public Collection<Object> values() {
		Properties properties = PropertyHolder.getProperties();
		return properties.values();
	}

}
